﻿@inherits LayoutComponentBase
@inject NavigationManager NavigationManager
@inject IdentityAuthenticationStateProvider authStateProvider

<MApp>
    <MMain>

        <div style="display: flex;flex-wrap: nowrap;height: 100%;">
            <div>
                <MNavigationDrawer Dark Class="text--darken" Color="#001529" @bind-MiniVariant="_mini">
                    <PrependContent>
                        <MListItem Class="px-2" OnClick="@(e=>_mini = !_mini)">
                            <MListItemAvatar Size="40">
                                <MImage Src="@("/imgs/avatar.jpg")"></MImage>
                            </MListItemAvatar>

                            <AuthorizeView>
                                <Authorized>
                                    <MListItemTitle>@context.User.Identity.Name</MListItemTitle>
                                </Authorized>
                                <NotAuthorized>
                                    <MListItemTitle>Administrator</MListItemTitle>
                                </NotAuthorized>
                            </AuthorizeView>


                        </MListItem>
                    </PrependContent>

                    <ChildContent>
                        <MList Dense Nav Dark>
                            @foreach (var item in _items)
                            {
                                <MListItem Link OnClick="@(e=>GoToLink(item.Link))">
                                    <MListItemIcon>
                                        <MIcon>@item.Icon</MIcon>
                                    </MListItemIcon>

                                    <MListItemContent>
                                        <MListItemTitle>@item.Title</MListItemTitle>
                                    </MListItemContent>
                                </MListItem>
                            }
                        </MList>
                    </ChildContent>
                </MNavigationDrawer>
            </div>
            <div style="flex: 1;background-color: #f0f2f5">
                <MAppBar Color="white" Dense>
                    <MButton Icon OnClick="() => _mini = !_mini">
                        <MIcon>@(_mini ? "mdi-chevron-right" : "mdi-chevron-left")</MIcon>
                        </MButton>

                        <MToolbarTitle></MToolbarTitle>

                        <MSpacer></MSpacer>


                        <MMenu Left
                           Bottom>
                            <ActivatorContent>
                                <MButton Icon @attributes="@context.Attrs">
                                    <MIcon>mdi-dots-vertical</MIcon>
                                </MButton>
                            </ActivatorContent>
                            <ChildContent>
                                <MList>
                                    @*<MListItem OnClick="() => {}">
                                <MListItemTitle>个人信息</MListItemTitle>
                                </MListItem>*@
                                    <MListItem OnClick="Logout">
                                        <MListItemTitle>注销登录</MListItemTitle>
                                    </MListItem>
                                </MList>
                            </ChildContent>
                        </MMenu>
                    </MAppBar>

                    <MCard Elevation="4" Style="margin: 15px;height: calc(100% - 80px);">
                        <MCardText Class="text--primary">
                            @Body
                        </MCardText>
                    </MCard>
                </div>
            </div>

        </MMain>
    </MApp>


    @code {

    private bool _mini = true;

    class Item
    {
        public string Title { get; set; }
        public string Icon { get; set; }
        public string Link { get; set; }
    }

    private Item[] _items = new Item[]
    {
        new Item{ Title= "控制台", Icon= "mdi-view-dashboard",Link = "/admin/" },
        new Item { Title= "视频管理", Icon= "mdi-movie",Link = "/admin/vmanage" },
        new Item { Title= "链接管理", Icon= "mdi-link",Link = "/admin/vlmanage" },
        new Item { Title= "年评管理", Icon= "mdi-comment",Link = "/admin/armanage" },
        new Item { Title= "视频采集", Icon= "mdi-cloud-download",Link = "/admin/collect" },
    };


    // 链接跳转
    private void GoToLink(string link)
    {
        NavigationManager.NavigateTo(link);
    }

    // 注销登录
    private async Task Logout()
    {
        await authStateProvider.Logout();
    }
}